﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySql.Data.MySqlClient;

namespace AlphaSolutionsGP
{
    public class Assesment
    {
        #region Properties
        private int _assesmentID;
        private string _moduleCode;
        private string _status;
        private string _handOutDate;
        private string _dueInDate;
        private int _weightingPercentage;
        private string _type;
        private string _description;
        //private int assessment_ID;
        //private string module_Code;
        //private DateTime hand_out_date;
        //private DateTime due_in_date;
        //private int weighting;
        //private string description;
        #endregion

        #region Constructors
        //default
        public Assesment()
        {
            _assesmentID = 0;
            _moduleCode = "";
            _status = "";
            _handOutDate = "2012-12-11";
            _dueInDate = "2023-01-01";
            _weightingPercentage = 0;
            _type = "";
            _description = "";
        }

        public Assesment(int assesmentID, string moduleCode, string status, string handoutdate, string dueindate, int weighting, string type, string description)
        {
            this._assesmentID = assesmentID;
            this._moduleCode = moduleCode;
            this._status = status;
            this._handOutDate = handoutdate;
            this._dueInDate = dueindate;
            this._weightingPercentage = weighting;
            this._type = type;
            this._description = description;
        }

        //public Assesment(int assessment_ID, string module_Code, string status, DateTime hand_out_date, DateTime due_in_date, int weighting, string type, string description)
        //{
        //    // TODO: Complete member initialization
        //    this.assessment_ID = assessment_ID;
        //    this.module_Code = module_Code;
        //    this.Status = status;
        //    this.hand_out_date = hand_out_date;
        //    this.due_in_date = due_in_date;
        //    this.weighting = weighting;
        //    this.Type = type;
        //    this.description = description;
        //}
        #endregion

        #region getters and setters
        public string Desc
        {
            get { return _description; }
            set { _description = value; }
        }
        public string Type
        {
            get { return _type; }
            set { _type = value; }
        }
        
        public int WeightingPercentage
        {
            get { return _weightingPercentage; }
            set { _weightingPercentage = value; }
        }
        
        public string DueInDate
        {
            get { return _dueInDate; }
            set { _dueInDate = value; }
        }
        

        public string HandOutDate
        {
            get { return _handOutDate; }
            set { _handOutDate = value; }
        }
        

        public string Status
        {
            get { return _status; }
            set { _status = value; }
        }
        
        public string ModuleCode
        {
            get { return _moduleCode; }
            set { _moduleCode = value; }
        }
        

        public int AssesmentID
        {
            get { return _assesmentID; }
            set { _assesmentID = value; }
        }
        #endregion

        #region methods
        public void createAssessment()
        {
            MySqlConnection connection = new MySqlConnection("server=194.81.104.22;" + "User Id=alpha;" + "database=alpha_db;" + "password=bravo;");
            try
            {
                connection.Open();
            }
            catch
            {
                System.Windows.Forms.MessageBox.Show("Connection failed");
            }
            try
            {
               // frmStudentProfile form = new frmStudentProfile();
                MySqlCommand cmd = connection.CreateCommand();
                cmd.CommandText = "insert into ASSESSMENT(assessment_ID, MODULE_module_Code, status, hand_out_date, due_in_date, weighting_percentage, type, description) values('" + _assesmentID + "','" + _moduleCode + "','" + _status  + "','" + _handOutDate + "','" + _dueInDate + "','" + _weightingPercentage + "' , '" + _type + "', '" + _description + "');";
                MySqlDataReader run = cmd.ExecuteReader();
                System.Windows.Forms.MessageBox.Show("The Assessment has been inserted.\n\nDescription: " + this._description, "Insert OK", System.Windows.Forms.MessageBoxButtons.OK);
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("Unable to insert due to the following error:\n\n" + ex.ToString());
            }
        }

        public void removeAssessment()
        {
            MySqlConnection connection = new MySqlConnection("server=194.81.104.22;" + "User Id=alpha;" + "database=alpha_db;" + "password=bravo;");
            try
            {
                connection.Open();
            }
            catch
            {
                System.Windows.Forms.MessageBox.Show("Connection failed");
            }
            try
            {
                MySqlCommand cmd = connection.CreateCommand();
                cmd.CommandText = "DELETE FROM ASSESSMENT WHERE assessment_ID=" + _assesmentID;
                MySqlDataReader run = cmd.ExecuteReader();
                System.Windows.Forms.MessageBox.Show("The Assessment ("+this._assesmentID+") has been deleted.", "Delete OK", System.Windows.Forms.MessageBoxButtons.OK);
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("Unable to delete due to the following error:\n\n" + ex.ToString());
            }
        }

        public void amendAssessment()
        {
            //connection string to be added here
            //command
            MySqlConnection connection = new MySqlConnection("server=194.81.104.22;" + "User Id=alpha;" + "database=alpha_db;" + "password=bravo;");
            try
            {
                connection.Open();
            }
            catch
            {
                System.Windows.Forms.MessageBox.Show("Connection failed");
            }
            try
            {
                MySqlCommand cmd = connection.CreateCommand();
                cmd.CommandText = "UPDATE ASSESSMENT SET MODULE_module_Code='" + _moduleCode + "', status='" + _status + "', hand_out_date='" + _handOutDate + "', due_in_date='" + _dueInDate + "', weighting_percentage='" + _weightingPercentage + "', type='" + _type + "', description='" + _description +"' WHERE assessment_ID=" + _assesmentID;
                MySqlDataReader run = cmd.ExecuteReader();
                System.Windows.Forms.MessageBox.Show("The assessment ("+this._assesmentID+") has been updated.", "Successfully Modified.", System.Windows.Forms.MessageBoxButtons.OK);
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("Unable to add due to the following error:\n\n" + ex.ToString());
            }
        }
        #endregion
    }
}
